import * as types from "../types/updateInfoTypes";

const initialState = {
  loading: false,
  initing: true,
  error: undefined,
  updateModels: [],
  updateStandard: [],
  curUpdateStandard: undefined,
};

export default function updateInfoReducer(state = initialState, action) {
  switch (action.type) {
    case types.UPDATEINFO_INITING:
      return {
        ...state,
        initing: true,
      };
    case types.UPDATEINFO_DONE:
      return {
        ...state,
        loading: false,
        updateModels: action.updateModels,
      };
    case types.UPDATEINFO_ERROR:
      return {
        ...state,
        initing: false,
        loading: false,
        error: action.error,
      };
    case types.UPDATEINFO_STANDARD_INITING:
      return {
        ...state,
        loading: true,
      };
    case types.UPDATEINFO_STANDARD_DONE:
      return {
        ...state,
        initing: false,
        loading: false,
        updateStandard: action.updateStandard,
        curUpdateStandard: action.curUpdateStandard,
      };
    case types.UPDATEINFO_STANDARD_ERROR:
      return {
        ...state,
        initing: false,
        loading: false,
        error: action.error,
      };
    case types.UPDATEINFO_UPDATESTANDARDCHANGE:
      return {
        ...state,
        curUpdateStandard: action.curUpdateStandard,
      };
    case types.UPDATEINFO_UNMOUNT:
      return {
        ...initialState,
      };
    default:
      return state;
  }
}
